package com.google.tts;

import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.ServiceConnection;
import android.content.pm.PackageManager;
import android.content.pm.PackageManager.NameNotFoundException;
import android.os.IBinder;
import android.os.RemoteException;
import android.util.Log;

public class TTS
{
  private static final int MIN_VER = 10;
  private InitListener cb = null;
  private Context ctx;
  private ITTS itts;
  private ITTSCallback ittscallback;
  private ServiceConnection serviceConnection;
  private boolean showInstaller = false;
  private SpeechCompletedListener speechCompletedCallback = null;
  private boolean started = false;
  private int version = -1;
  private TTSVersionAlert versionAlert = null;

  public TTS(Context paramContext, InitListener paramInitListener, TTSVersionAlert paramTTSVersionAlert)
  {
    this.showInstaller = true;
    this.versionAlert = paramTTSVersionAlert;
    this.ctx = paramContext;
    this.cb = paramInitListener;
    if (!(dataFilesCheck()))
      return;
    initTts();
  }

  public TTS(Context paramContext, InitListener paramInitListener, boolean paramBoolean)
  {
    this.showInstaller = paramBoolean;
    this.ctx = paramContext;
    this.cb = paramInitListener;
    if (!(dataFilesCheck()))
      return;
    initTts();
  }

  private boolean dataFilesCheck()
  {
    int i;
    if (!(ConfigurationManager.allFilesExist()))
      if (!(this.showInstaller))
        i = 0;
    while (true)
    {
      return i;
      try
      {
        Context localContext = this.ctx.createPackageContext("com.google.tts", 3);
        Intent localIntent = new Intent(localContext, localContext.getClassLoader().loadClass("com.google.tts.ConfigurationManager"));
        this.ctx.startActivity(localIntent);
        label69: i = 0;
      }
      catch (PackageManager.NameNotFoundException localNameNotFoundException)
      {
        localNameNotFoundException.printStackTrace();
        i = 1;
      }
      catch (ClassNotFoundException localClassNotFoundException)
      {
        localClassNotFoundException.printStackTrace();
        break label69:
      }
    }
  }

  private void initTts()
  {
    this.started = false;
    this.serviceConnection = new ServiceConnection()
    {
      public void onServiceConnected(ComponentName paramComponentName, IBinder paramIBinder)
      {
        TTS.this.itts = ITTS.Stub.asInterface(paramIBinder);
        try
        {
          TTS.this.version = TTS.this.itts.getVersion();
          if (TTS.this.version >= 10)
            break label111;
          if (!(TTS.this.showInstaller))
            return;
          if (TTS.this.versionAlert != null)
          {
            TTS.this.versionAlert.show();
            return;
          }
          new TTSVersionAlert(TTS.this.ctx, null, null, null).show();
        }
        catch (RemoteException localRemoteException)
        {
          TTS.this.initTts();
        }
        return;
        label111: TTS.this.ittscallback = new 1(this);
        TTS.this.itts.registerCallback(TTS.this.ittscallback);
        TTS.this.started = true;
        if (TTS.this.cb == null)
          return;
        TTS.this.cb.onInit(TTS.this.version);
      }

      public void onServiceDisconnected(ComponentName paramComponentName)
      {
        TTS.this.itts = null;
        TTS.this.cb = null;
        TTS.this.started = false;
      }
    };
    Intent localIntent = new Intent("android.intent.action.USE_TTS");
    localIntent.addCategory("android.intent.category.TTS");
    if ((!(this.ctx.bindService(localIntent, this.serviceConnection, 1))) && (this.showInstaller))
    {
      if (this.versionAlert == null)
        break label73;
      this.versionAlert.show();
    }
    while (true)
    {
      return;
      label73: new TTSVersionAlert(this.ctx, null, null, null).show();
    }
  }

  public static boolean isInstalled(Context paramContext)
  {
    PackageManager localPackageManager = paramContext.getPackageManager();
    Intent localIntent = new Intent("android.intent.action.USE_TTS");
    localIntent.addCategory("android.intent.category.TTS");
    if (localPackageManager.resolveService(localIntent, 0) == null);
    for (int i = 0; ; i = 1)
      return i;
  }

  public void addSpeech(String paramString1, String paramString2)
  {
    if (!(this.started));
    while (true)
    {
      return;
      try
      {
        this.itts.addSpeechFile(paramString1, paramString2);
      }
      catch (RemoteException localRemoteException)
      {
        this.started = false;
        initTts();
      }
      catch (NullPointerException localNullPointerException)
      {
        this.started = false;
        initTts();
      }
      catch (IllegalStateException localIllegalStateException)
      {
        this.started = false;
        initTts();
      }
    }
  }

  public void addSpeech(String paramString1, String paramString2, int paramInt)
  {
    if (!(this.started));
    while (true)
    {
      return;
      try
      {
        this.itts.addSpeech(paramString1, paramString2, paramInt);
      }
      catch (RemoteException localRemoteException)
      {
        this.started = false;
        initTts();
      }
      catch (NullPointerException localNullPointerException)
      {
        this.started = false;
        initTts();
      }
      catch (IllegalStateException localIllegalStateException)
      {
        this.started = false;
        initTts();
      }
    }
  }

  public int getVersion()
  {
    return this.version;
  }

  public boolean isSpeaking()
  {
    int i;
    if (!(this.started))
      i = 0;
    while (true)
    {
      return i;
      try
      {
        boolean bool = this.itts.isSpeaking();
        label39: i = bool;
      }
      catch (RemoteException localRemoteException)
      {
        this.started = false;
        initTts();
        i = 0;
      }
      catch (NullPointerException localNullPointerException)
      {
        this.started = false;
        initTts();
        break label39:
      }
      catch (IllegalStateException localIllegalStateException)
      {
        this.started = false;
        initTts();
        break label39:
      }
    }
  }

  public void playEarcon(TTSEarcon paramTTSEarcon, int paramInt, String[] paramArrayOfString)
  {
    playEarcon(paramTTSEarcon.name(), paramInt, paramArrayOfString);
  }

  public void playEarcon(String paramString, int paramInt, String[] paramArrayOfString)
  {
    if (!(this.started));
    while (true)
    {
      return;
      try
      {
        this.itts.playEarcon(paramString, paramInt, paramArrayOfString);
      }
      catch (RemoteException localRemoteException)
      {
        this.started = false;
        initTts();
      }
      catch (NullPointerException localNullPointerException)
      {
        this.started = false;
        initTts();
      }
      catch (IllegalStateException localIllegalStateException)
      {
        this.started = false;
        initTts();
      }
    }
  }

  public void setEngine(TTSEngine paramTTSEngine)
  {
    if (!(this.started));
    while (true)
    {
      return;
      try
      {
        this.itts.setEngine(paramTTSEngine.toString());
      }
      catch (RemoteException localRemoteException)
      {
        this.started = false;
        initTts();
      }
    }
  }

  public void setEngine(String paramString)
  {
    if (!(this.started));
    while (true)
    {
      return;
      try
      {
        this.itts.setEngine(paramString);
      }
      catch (RemoteException localRemoteException)
      {
        this.started = false;
        initTts();
      }
    }
  }

  public void setLanguage(String paramString)
  {
    if (!(this.started));
    while (true)
    {
      return;
      try
      {
        this.itts.setLanguage(paramString);
      }
      catch (RemoteException localRemoteException)
      {
        this.started = false;
        initTts();
      }
    }
  }

  public void setOnSpeechCompletedListener(SpeechCompletedListener paramSpeechCompletedListener)
  {
    this.speechCompletedCallback = paramSpeechCompletedListener;
  }

  public void setSpeechRate(int paramInt)
  {
    if (!(this.started));
    while (true)
    {
      return;
      try
      {
        this.itts.setSpeechRate(paramInt);
      }
      catch (RemoteException localRemoteException)
      {
        this.started = false;
        initTts();
      }
    }
  }

  public void showVersionAlert()
  {
    if (!(this.started));
    while (true)
    {
      return;
      if (this.versionAlert != null)
        this.versionAlert.show();
      new TTSVersionAlert(this.ctx, null, null, null).show();
    }
  }

  public void shutdown()
  {
    try
    {
      this.ctx.unbindService(this.serviceConnection);
      return;
    }
    catch (IllegalArgumentException localIllegalArgumentException)
    {
    }
  }

  public void speak(String paramString, int paramInt, String[] paramArrayOfString)
  {
    Log.i("TTS received: ", paramString);
    if (!(this.started));
    while (true)
    {
      return;
      try
      {
        this.itts.speak(paramString, paramInt, paramArrayOfString);
      }
      catch (RemoteException localRemoteException)
      {
        Log.e("TTS", "RemoteException error.");
        this.started = false;
        initTts();
      }
      catch (NullPointerException localNullPointerException)
      {
        Log.e("TTS", "NullPointerException error.");
        this.started = false;
        initTts();
      }
      catch (IllegalStateException localIllegalStateException)
      {
        Log.e("TTS", "IllegalStateException error.");
        this.started = false;
        initTts();
      }
    }
  }

  public void stop()
  {
    if (!(this.started));
    while (true)
    {
      return;
      try
      {
        this.itts.stop();
      }
      catch (RemoteException localRemoteException)
      {
        this.started = false;
        initTts();
      }
      catch (NullPointerException localNullPointerException)
      {
        this.started = false;
        initTts();
      }
      catch (IllegalStateException localIllegalStateException)
      {
        this.started = false;
        initTts();
      }
    }
  }

  public boolean synthesizeToFile(String paramString1, String[] paramArrayOfString, String paramString2)
  {
    int i;
    if (!(this.started))
      i = 0;
    while (true)
    {
      return i;
      try
      {
        boolean bool = this.itts.synthesizeToFile(paramString1, paramArrayOfString, paramString2);
        label45: i = bool;
      }
      catch (RemoteException localRemoteException)
      {
        this.started = false;
        initTts();
        i = 0;
      }
      catch (NullPointerException localNullPointerException)
      {
        this.started = false;
        initTts();
        break label45:
      }
      catch (IllegalStateException localIllegalStateException)
      {
        this.started = false;
        initTts();
        break label45:
      }
    }
  }

  public static abstract interface InitListener
  {
    public abstract void onInit(int paramInt);
  }

  public static abstract interface SpeechCompletedListener
  {
    public abstract void onSpeechCompleted();
  }
}

/* Location:           E:\Desktop\Android\wordstd\classes_dex2jar.jar
 * Qualified Name:     com.google.tts.TTS
 * JD-Core Version:    0.5.3
 */